import json
import os
import tqdm

path = '/media/hjh/workdir/0_Deep_Learning/磁瓦/测试数据集/语义分割（背面）/dataset/train/'

list_dir = os.listdir(path)

qx_class = []
qx_num = {}

for fp in tqdm.tqdm(list_dir):
    if fp.endswith('.json'):
        with open(path + fp, 'r', encoding='utf-8') as jsonFile:
            data = json.load(jsonFile)
            shapes = data['shapes']
            for i in shapes:
                label = i['label']
                if label not in qx_class:
                    qx_class.append(label)
                    qx_num[label] = 1
        
                else:
                    qx_num[label] += 1


print('缺陷类别有：', qx_class)
print('各缺陷个数为：', qx_num)